const city = require('./src/mock/city.json')
const Mock = require('mockjs')
const { list } = require('./src/mock')
const bodyParser = require('body-parser')
module.exports = {
	devServer: {
		before(app) {
			app.use(bodyParser.json())
			// 选车
			app.get('/api/city/list', (req, res) => res.send(city))
			// 选车页面蒙层 弹框数据
			app.get('/api/list', (req, res) => {
				res.send({ code: 200, data:list })
			})

			// 车系详情
			app.post('/api/car/info', (req, res) => {
				const { id } = req.body
				const carInfo = list.find(v => v.id === id)
				res.send({
					code: 200,
					data: carInfo
				})
			})

			// 首页
			app.get('/api/home/list', (req, res) => {
				const list = Mock.mock({
					'list|8': [{
						'type|1-3': 1,
						"urls|3": ['@image(120x80, @color)'],
						'rightUrl': '@image(100x100, @color)',
						"bigUrl": '@image(300x200, @color)',
						"title": '@ctitle',
						"auther": '@cname',
						"createTime": '@datetime',
						"id": '@id',
						"desc": '@cword(10, 20)'
					}]
				})
				res.send({
					code: 200,
					data: list.list
				})
			})
		}
	}
}